package com.student.dong.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.student.dong.entity.SysUser;
import com.student.dong.service.UserService;
import com.student.dong.utils.Result;
import com.student.dong.vo.StudentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.student.dong.domain.AlgsStudent;
import com.student.dong.service.IAlgsStudentService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * (注册)学生信息Controller
 * 
 * @author ruoyi
 * @date 2023-03-15
 */
@RestController
@RequestMapping("/student")
public class AlgsStudentController extends BaseController
{
    @Autowired
    private IAlgsStudentService algsStudentService;


    @Autowired
    private UserService userService;

    /**
     * 查询(注册)学生信息列表
     */
    //@RequiresPermissions("student:student:list")
    @GetMapping("/list")
    public TableDataInfo list(StudentVo studentVo)
    {
        startPage();
        List<StudentVo> list = algsStudentService.selByType(studentVo);
        for (StudentVo vo : list) {
            System.out.println(vo);
        }
        return getDataTable(list);
    }

    /**
     * 导出(注册)学生信息列表
     */
    //@RequiresPermissions("student:student:export")
    @Log(title = "(注册)学生信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AlgsStudent studentVo)
    {
        List<AlgsStudent> list = algsStudentService.selectAlgsStudentList(studentVo);
        ExcelUtil<AlgsStudent> util = new ExcelUtil<AlgsStudent>(AlgsStudent.class);
        util.exportExcel(response, list, "(注册)学生信息数据");
    }

    /**
     * 获取(注册)学生信息详细信息
     */
    //@RequiresPermissions("student:student:query")
    @GetMapping(value = "/{studentId}")
    public AjaxResult getInfo(@PathVariable("studentId") Long studentId)
    {
        return success(algsStudentService.selectAlgsStudentByStudentId(studentId));
    }

    /**
     * 新增(注册)学生信息
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody AlgsStudent algsStudent)
    {
        SysUser sysUser = userService.selByName(algsStudent.getStudentName());
        System.out.println(sysUser);
        algsStudent.setUserId(sysUser.getUserId());
        return toAjax(algsStudentService.insertAlgsStudent(algsStudent));
    }


    /**
     * 根据用户名查询对象
     */
    //@RequiresPermissions("student:student:edit")
    @Log(title = "(注册)学生信息", businessType = BusinessType.UPDATE)
    @PutMapping("/selOne")
    public Result selByUserName(@RequestBody AlgsStudent algsStudent)
    {

        return Result.ok().data("stu",algsStudentService.selByStudentName(algsStudent.getStudentName()));
    }

    /**
     * 修改(注册)学生信息
     */
    //@RequiresPermissions("student:student:edit")
    @Log(title = "(注册)学生信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AlgsStudent algsStudent)
    {
        return toAjax(algsStudentService.updateAlgsStudent(algsStudent));
    }

    /**
     * 删除(注册)学生信息
     */
    //@RequiresPermissions("student:student:remove")
    @Log(title = "(注册)学生信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{studentIds}")
    public AjaxResult remove(@PathVariable Long[] studentIds)
    {
        return toAjax(algsStudentService.deleteAlgsStudentByStudentIds(studentIds));
    }
}
